<?php
/**********************************************************************
 *                                                                    *    
 * Copyright (c) 2009 Dmytro Bezhnar. All rights reserved.  			      *
 *                                                                    *
 **********************************************************************/

/**
 * Memcache persistable object.
 *
 * @version $Id: Memcached.php,v 1.1 2007/05/22 05:02:40 demonit Exp $
 */

class Memcached {
	
	
	/**
     * Memcache connection
     * @var Memcache
     */
    private $memcache = null;
    
	
	function __construct()
    {
    	global $options, $memcache;
    	
    	if ($options['memcache']['enable'])
    	{
    		if (!is_object($memcache))
    		{
    			$memcache = new Memcache();
    			$memcache->connect($options['memcache']['host'], $options['memcache']['port']);
    		}
    		$this->memcache=$memcache;
			$this->memcache_name=$GLOBALS['options']['memcache']['name'].'_'.$this->class_name;
    	}
    }
    
    function set($name,$value,$time,$use_compression=0)
    {
    	$this->memcache->set($name,$value,$use_compression,$time);
    }
	
    function get($name)
    {
    	return $this->memcache->get($name);
    }
    
    /**
	 * Make memcache name
	 * @param string $qs
	 * @param string $name
	 */
    public function getName($qs,$name) {
    	if ($name!='') {
    		$key = $name;
    	} else{
    		$key = $this->memcache_name.'_'.crc32($qs); 
    	}
    	return $key.'_'.$_SESSION['lang_mysql_charset'];        
    }                                                                                                                   
}
?>